package com.example.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author zhangs
 * @version v1.0
 * @decription Servlet 03 转发到jsp
 * @date 2021/3/23 21:06
 **/
@WebServlet(urlPatterns = "/demo03")
public class Demo03 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        // 往Request域中存放内容
        req.setAttribute("name", "Bob");
        // 请求转发到jsp页面
        req.getRequestDispatcher("/WEB-INF/views/index.jsp").forward(req, resp);
        // 获取在jsp中存储的对象
        System.out.println(req.getAttribute("age"));
    }
}
